package com.zhanghu.builder.other_builder;

import com.zhanghu.builder.ComputerBuilder;

/**
 * @Author: zhanghu
 * @Description: 使用静态内部类的方式使用建造者模式，使创建的对象更灵活
 * @Date: Create in 10:27 2020/1/17
 * @modified by:
 */

public class Computer {
    private String screen;
    private String mouse;
    private String keyboard;

    /**
     * 构造函数将builder的值传入computer
     * @param computerBuilder
     */
    private Computer(ComputerBuilder computerBuilder) {

        this.screen = computerBuilder.screen;
        this.keyboard = computerBuilder.keyboard;
        this.mouse = computerBuilder.mouse;
    }

    /**
     * 静态内部类使用建造者模式创建对象
     */
    static class ComputerBuilder {
        private String screen;
        private String mouse;
        private String keyboard;

        public ComputerBuilder buildScreen(String screen) {
            this.screen = screen;
            return this;
        }

        ComputerBuilder buildMouse(String mouse) {
            this.mouse = mouse;
            return this;
        }

        ComputerBuilder buildKeyboard(String keyboard) {
            this.keyboard = keyboard;
            return this;
        }


        Computer getComputer() {
            return new Computer(this);
        }

    }


    public String getScreen() {
        return screen;
    }

    public void setScreen(String screen) {
        this.screen = screen;
    }

    public String getMouse() {
        return mouse;
    }

    public void setMouse(String mouse) {
        this.mouse = mouse;
    }

    public String getKeyboard() {
        return keyboard;
    }

    public void setKeyboard(String keyboard) {
        this.keyboard = keyboard;
    }

    @Override
    public String toString() {
        return "Computer{" +
                "screen='" + screen + '\'' +
                ", mouse='" + mouse + '\'' +
                ", keyboard='" + keyboard + '\'' +
                '}';
    }
}
